﻿<?php
error_reporting(E_ERROR|E_PARSE);
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录!');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
?>
<?php
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
function trimd($str){
$str=str_replace("'","''",$str);
return trim($str);
}
$id=intval($_GET["id"]);
$platform=$_GET["platform"];
$ylang=$_POST["ylang"];
$lang=$_POST["lang"];

$sqls="select * from ph_".$ylang." where ID='".$id."'";
$results=mysqli_query($conn,$sqls);
$rows=mysqli_fetch_array($results);
$price=$rows["price"];
$saleprice=$rows["saleprice"];
$skucode=$rows["skucode"];
$coin=$rows["coin"];
$code=$rows["code"];
$bname=$rows["bname"];
$weight=$rows["weight"];
$kucun=$rows["kucun"];
$shopname=$rows["shopname"];
$platform=$rows["platform"];
$sid=$rows["sid"];
$btname=$rows["btname"];
$fromurl=$rows["fromurl"];
$isedit=$rows["isedit"];
$user_name=$_SESSION["managername"];
$ndate=date("Y-m-d",time());

for($i=0;$i<count($lang);$i++){
$html=file_get_contents("http://".$_SERVER['HTTP_HOST']."/products/getfanyi.php?id=".$id."&lang=".$lang[$i]);
$thtml=explode("|||",trimd($html));
$proname=ucwords($thtml[0]);
$content=$thtml[1];
$des=$thtml[2];
$keywords=$thtml[3];


$sqql="CREATE TABLE IF NOT EXISTS ph_".$lang[$i]."(ID int,proname varchar(500),price float,saleprice float,coin varchar(500),code varchar(500),content text,ndate varchar(500),skucode varchar(500),user_name varchar(500),bname varchar(500),lang varchar(500),weight varchar(500),keywords text,des text,kucun int,platform varchar(500),sketch text,shopname varchar(500),sid int,isedit varchar(500),btname varchar(500),fromurl varchar(500))";
mysqli_query($conn,$sqql);

if(!empty($proname)&&!empty($content)){
$sqlm="select * from ph_".$lang[$i]." where ID='".$id."' and user_name='".$user_name."'";
$resultm=mysqli_query($conn,$sqlm);
if(mysqli_num_rows($resultm)<1){

$sql = "INSERT INTO ph_".$lang[$i]."(ID,proname,price,skucode,coin,code,content,ndate,bname,user_name,lang,sketch,keywords,weight,saleprice,kucun,platform,shopname,sid,isedit,btname,fromurl)VALUES('".$id."','".$proname."','".$price."','".$skucode."','".$coin."','".$code."','".$content."','".$ndate."','".$bname."','".$user_name."','".$lang."','".$des."','".$keywords."','".$weight."','".$saleprice."','".$kucun."','".$platform."','".$shopname."','".$sid."','".$isedit."','".$btname."','".$fromurl."')";

mysqli_query($conn,$sql);

}else{
$sql = "update ph_".$lang[$i]." set proname='".$proname."',sketch='".$des."',keywords='".$keywords."',content='".$content."' where ID='".$id."'";
mysqli_query($conn,$sql);

}

}
echo "<script language=JavaScript>\r\n";
echo "alert('提交成功!');\r\n";
echo "location.href='productslist.php?bname=".$bname."&lang=".$ylang."&platform=".$platform."'\r\n";
echo "</script>";
}
?>
<?php }?>